import { createApp } from "vue";
import {
  ElButton,
  ElContainer,
  ElAside,
  ElMenu,
  ElSubMenu,
  ElMenuItemGroup,
  ElMenuItem,
  ElForm,
  ElFormItem,
  ElInput,
  ElCheckbox,
  ElPopover,
  ElTag,
  ElCard,
  ElTable,
  ElUpload,
  ElDialog,
  ElPagination,
  ElCascader,
  ElRadioGroup,
  ElRadio,
  ElSelect,
  ElOption,
} from "element-plus";
import App from "./App.vue";
import router from "./router";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";

const app = createApp(App);

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.use(router);

app.use(ElButton);
app.use(ElContainer);
app.use(ElAside);
app.use(ElMenu);
app.use(ElSubMenu);
app.use(ElMenuItemGroup);
app.use(ElMenuItem);
app.use(ElForm);
app.use(ElFormItem);
app.use(ElInput);
app.use(ElCheckbox);
app.use(ElPopover);
app.use(ElTag);
app.use(ElCard);
app.use(ElTable);
app.use(ElUpload);
app.use(ElDialog);
app.use(ElPagination);
app.use(ElCascader);
app.use(ElRadioGroup);
app.use(ElRadio);
app.use(ElSelect);
app.use(ElOption);

const orderStatus = {
  0: "待支付",
  1: "已支付",
  2: "配货完成",
  3: "出库成功",
  4: "交易成功",
  "-1": "手动关闭",
  "-2": "超时关闭",
  "-3": "商家关闭",
};

app.config.globalProperties.$filters = {
  orderMap(status) {
    return orderStatus[status] || "未知状态";
  },
  prefix(url) {
    if (url && url.startsWith("http")) {
      return url;
    } else {
      url = `http://backend-api-02.newbee.ltd${url}`;
      return url;
    }
  },
};
app.config.globalProperties.goTop = function () {
  const main = document.querySelector(".main");
  main.scrollTop = 0;
};

app.mount("#app");
